//
//  XCWebViewViewController.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/11.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCWebViewViewController.h"
#import "XCSingleBottumView.h"

@interface XCWebViewViewController ()<UIWebViewDelegate>

@property (nonatomic, retain) UIActivityIndicatorView *action;
@property (nonatomic, copy) NSString *value;

@end

@implementation XCWebViewViewController
- (instancetype)initWithString:(NSString *)value
{
    self = [super init];
    if (self) {
        self.value = value;
    }
    return self;
}
- (void)dealloc {
    _webView.delegate = nil;
    [_action release];
    [_value release];
    [_webView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    
    if ([self.value  isEqual: @"2330136"]) {
       NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tms.xiami.com/market/music/smfamilydongting.php?id=109"]];
        [self.webView loadRequest:request];
    } else if ([self.value isEqualToString:@"http://alimusic.xiami.com/markets/xiami/gary-friends"]) {
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tms.xiami.com/market/music/dongtinghotbang15.php?id=107"]];
        [self.webView loadRequest:request];
    } else {
        
         NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:self.value]];
        [self.webView loadRequest:request];
    }

    self.webView.delegate = self;
    
    [self.view addSubview:self.webView];
    [_webView release];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"Image-leftBarButton"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction)];
}
//  webView
- (void)webViewDidStartLoad:(UIWebView *)webView {
    UIView *view = [[UIView alloc] initWithFrame:self.view.bounds];
    [view setTag:1000];
    [view setBackgroundColor:[UIColor colorWithRed:0.981 green:1.000 blue:0.918 alpha:1.000]];
    view.alpha = 0.5;
    self.action = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [self.action setCenter:view.center];
    [self.action setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [self.view addSubview:view];
    [view addSubview:self.action];
    [self.action startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.action stopAnimating];
    UIView *view = (UIView *)[self.view viewWithTag:1000];
    [view removeFromSuperview];
}
- (void)viewWillAppear:(BOOL)animated {
    [XCSingleBottumView shareBottomViewBuild].hidden = YES;
}
//- (void)viewWillDisappear:(BOOL)animated {
//    [XCSingleBottumView shareBottomViewBuild].hidden = YES;
//}

- (void)leftBarButtonItemAction {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   
}



@end
